package com.lonely.system.enums;

import cloud.tianai.captcha.common.constant.CaptchaTypeConstant;

import java.util.Objects;
import java.util.Random;

public enum CaptchaType {
    SLIDER(CaptchaTypeConstant.SLIDER, 1),
    ROTATE(CaptchaTypeConstant.ROTATE, 2),
    CONCAT(CaptchaTypeConstant.CONCAT, 3),
    WORD_IMAGE_CLICK(CaptchaTypeConstant.WORD_IMAGE_CLICK, 4);

    private final String captchaType;
    private final Integer typeCode;

    CaptchaType(String captchaType, Integer typeCode) {
        this.captchaType = captchaType;
        this.typeCode = typeCode;
    }

    public String getCaptchaType() {
        return captchaType;
    }

    public Integer getTypeCode() {
        return typeCode;
    }

    public static String getCaptchaTypeByTypeCode(Integer typeCode) {
        for (CaptchaType captchaType : CaptchaType.values()) {
            if (Objects.equals(captchaType.getTypeCode(), typeCode)) {
                return captchaType.getCaptchaType();
            }
        }

        return getCaptchaTypeByTypeCode(new Random().nextInt(4) + 1);
    }

}

